"""
tube.py --                                                                                            
                                                                                                                                                                                                        
It sets a tube's geometric properties.                                              
                                                                                                                                                                                                            
Date of creation: 2007-03-17                                                                        
                                                                                                                                                                                                
Copyright  Robotics and Automation Group, Pontificia Universidad Javeriana - Cali.                  
    Freddy Naranjo Perez, fnaranjo@puj.edu.co                                                                   
    Antonio Alejandro Matta Gomez amatta@puj.edu.co                                      
    Julian David Colorado, jdcolorado@puj.edu.co                           
    Juan Camilo Acosta Mejia, jcacosta@puj.edu.co                                    
                                                                                                                                                                                                        
See the file "license.terms" for information on usage and redistribution of this file, and for a    
DISCLAIMER OF ALL WARRANTIES.
"""

import vtk
from vtk.util.colors import *

class Tube:
  def __init__( self, ren, geomdim, posorient, lighting, color ):
        """ Inits a tube's 3d object and its associated color and lighting"""
        
        #tube points.
        self.tubepoints = vtk.vtkPoints()
        self.tubepoints.InsertPoint(0, 0.0, 0.0, 0.0)
        self.tubepoints.InsertPoint(1, 0.0, geomdim[1], 0.0)
        #tube cell.
        self.tubecell = vtk.vtkCellArray()
        self.tubecell.InsertNextCell(2) # cells' number of points
        self.tubecell.InsertCellPoint(0)
        self.tubecell.InsertCellPoint(1)
        #both points and cells are associated in a PolyData set.
        self.profile = vtk.vtkPolyData()
        self.profile.SetPoints(self.tubepoints)
        self.profile.SetLines(self.tubecell)

        # Give shape to the resulting line via the Tube Filter.
        self.profileTubes = vtk.vtkTubeFilter()
        self.profileTubes.SetNumberOfSides(20)
        self.profileTubes.SetInput(self.profile)
        self.profileTubes.SetRadius(geomdim[3])
        self.profileTubes.SetVaryRadiusToVaryRadiusByVector ()
        
        #Smoothing applied in order to get a better surface.
        self.smooth= vtk.vtkSmoothPolyDataFilter()
        self.smooth.SetInputConnection(self.profileTubes.GetOutputPort())
        self.smooth.SetNumberOfIterations(20)
        
        #Normal's computation.
        self.normals = vtk.vtkPolyDataNormals()
        self.normals.SetInputConnection(self.smooth.GetOutputPort())
        
        #Normal's passed to the poly data mapper.
        self.map = vtk.vtkPolyDataMapper()
        self.map.SetInputConnection(self.normals.GetOutputPort())

        
        self.tubeActor = vtk.vtkActor()
        self.tubeActor.SetMapper(self.map)
        self.tubeActor.GetProperty().SetDiffuseColor(color)
        self.tubeActor.GetProperty().SetSpecular(.3)
        self.tubeActor.GetProperty().SetSpecularPower(30)
        self.tubeActor.SetPosition( posorient[0], posorient[1], posorient[2] )
        self.tubeActor.SetOrientation( posorient[3], posorient[4], posorient[5] )
            
        
    
        
    
    

        
        
            
        
    

    
  
  